/**
 * Author:yuiop
 * Date:2022/8/1 11:42
 */
package com.devops.admin.graphql;

import com.devops.admin.model.DOSRole;
import com.devops.admin.po.DOSRolePo;
import com.devops.admin.service.DOSRoleService;
import com.devops.admin.vo.DOSRoleVo;
import com.devops.common.annotation.DOSLog;
import com.devops.common.utils.Message;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@DgsComponent
public class DOSRoleDataFetcher {
    @Autowired
    DOSRoleService roleService;

    /**
     * @Author heyabo
     * @Description 添加角色
     * @Date 11:43 2022/8/29
     * @Param [dosRole]
     * @return com.devops.admin.model.DOSRole
     **/
    @DgsMutation
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR},logical = Logical.OR)
    @DOSLog(description = "添加角色")
    public DOSRole saveRole(@InputArgument DOSRoleVo dosRole){

        return roleService.saveRole(dosRole);
    }

    /**
     * @Author heyabo
     * @Description 更新角色信息
     * @Date 13:55 2022/8/29
     * @Param [dosRole]
     * @return com.devops.admin.model.DOSRole
     **/
    @DgsMutation
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR},logical = Logical.OR)
    @DOSLog(description = "更新角色信息")
    public DOSRole updateRole(@InputArgument DOSRoleVo dosRole){

        return roleService.updateRole(dosRole);
    }

    /**
     * @Author heyabo
     * @Description 删除角色
     * @Date 14:10 2022/8/29
     * @Param [roleId]
     * @return java.lang.Boolean
     **/
    @DgsMutation
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR},logical = Logical.OR)
    @DOSLog(description = "删除角色")
    public Boolean deleteRole(@InputArgument Integer roleId){

        return roleService.deleteRole(roleId);
    }

    /**
     * @Author heyabo
     * @Description 为角色绑定菜单
     * @Date 14:39 2022/8/29
     * @Param [roleVo]
     * @return com.devops.common.utils.Message
     **/
    @DgsMutation
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR},logical = Logical.OR)
    @DOSLog(description = "为角色绑定菜单")
    public Message bindMenus(@InputArgument DOSRoleVo roleVo){

        return roleService.bindMenus(roleVo);
    }

    /**
     * @Author heyabo
     * @Description 查询所有的角色信息
     * @Date 19:47 2022/7/26
     * @Param []
     * @return java.util.List<com.devops.admin.model.DOSRole>
     **/
    @DgsQuery
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.LOGIN_USER},logical = Logical.OR)
    @DOSLog(description = "获取所有可用的用户角色信息")
    public List<DOSRole> getRoles() {
        return roleService.getUseable();
    }

    /**
     * @Author heyabo
     * @Description 查询所有的角色信息
     * @Date 15:37 2022/8/29
     * @Param [roleVo]
     * @return java.util.List<com.devops.admin.po.DOSRolePo>
     **/
    @DgsQuery
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR},logical = Logical.OR)
    @DOSLog(description = "查询所有的角色信息")
    public List<DOSRolePo> getAllRoles(@InputArgument DOSRoleVo roleVo){

        return roleService.getAllRoles(roleVo);
    }

}
